﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Configurations.Core;
using System.IO;
using Pixysoft.Framework.Configurations.Controller;

namespace Pixysoft.Framework.Configurations
{
    public class HtmlManager
    {
        public static IHtmlDocument Create()
        {
            return new HtmlDocument();
        }

        public static IHtmlDocument Import(string path)
        {
            if (!File.Exists(path))
                throw new Exception("file not existed.");

            return HtmlController.Instance.Deserialize(File.ReadAllText(path, Encoding.GetEncoding("gb2312")));
        }

        public static IHtmlDocument Deserialize(string value)
        {
            return HtmlController.Instance.Deserialize(value);
        }

        public static IHtmlNode DeserializeFragment(string value)
        {
            return HtmlController.Instance.DeserializeFragment(value);
        }

        public static string HtmlToPlain(string html)
        {
            if (string.IsNullOrEmpty(html))
                return html;

            return HtmlController.Instance.TransferToPlainContent(html);
        }
    }
}
